<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>$Title$</title>
</head>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/laypage.css">
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/laypage/laypage.js"></script>
<script type="text/javascript" src="/js/layer/layer.js"></script>
<script type="text/javascript" src="/js/vue/vue.min.js"></script>
<script type="text/javascript" src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<style>
    input.error {
        border: 1px solid red;
    }
</style>
<body>
<div class="container">
    <form id="editUserForm">
        <br/>
        <div class="form-group">
            <label for="username">用户名：</label>
            <input type="text" class="form-control" id="username" name="username" value="${user.username}" placeholder="输入名称">
        </div>
        <div class="form-group">
            <label for="password">密码：</label>
            <input type="password" class="form-control" id="password" name="password" value="${user.password}" placeholder="输入密码">
        </div>
        <div class="form-group">
            <label for="age">年龄：</label>
            <input type="text" class="form-control" id="powers" name="powers" value="${user.powers}" placeholder="输入年龄">
        </div>

        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">修改</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
        <input type="hidden" id="id" value="${user.id}"/>
    </form>
</div>
</body>
</html>
<script>
    //添加editDept
    var editDept = function () {

        if(!check().form()){
            return ;
        }
        $.ajax({
            type:'GET',
            dataType:'json',
            contentType:"application/json",
            url:'/free/editUser.do',
            data:{
                username:$("#username").val(),
                password:$("#password").val(),
                age:$("#age").val(),
                id:$("#id").val()
            },
            success:function () {
                alert("ok");
                $("#cancelBtn").click()
            },
            error:function () {
                alert("error");
            }
        });
    }

    //关闭遮罩层，更新页面信息
    $("#cancelBtn").on("click",function () {
        var index = parent.layer.getFrameIndex(window.name);
        //更新页面信息
        /*parent.getDeptPageList();*/
        parent.layer.close(index);
    })
    //点击提交按钮触发事件
    $("#saveBtn").on("click",function () {
        editDept();
    });

    function check() {
        return $("#editUserForm").validate({
            rules : {
                username : {
                    required:true
                },
                password : {
                    required:true
                },
                age : {
                    required:true
                }
            },
            messages:{
                username : {
                    required : ""
                },
                password : {
                    required : ""
                },
                age : {
                    required : ""
                }
            }
        })
    }
</script>